package com.jf.apply_car.util;

import com.jf.apply_car.bean.Userinfo;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class LoginUtil {
    private static ServletRequestAttributes getRequestAttributes() {
        return (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    }

    private static HttpServletRequest getRequest() {
        return getRequestAttributes().getRequest();
    }

    private static HttpSession getSession() {
        return getRequest().getSession();
    }

    public static Userinfo getLoginInfo() {
        return (Userinfo) getSession().getAttribute(MyConstants.LOGIN_SESSION_KEY);
    }

    public static int getLoginInfoId() {
        return getLoginInfo().getUserinfoId();
    }

    public static int getLoginRoleId() {
        return getLoginInfo().getRoleId();
    }

}
